//
//  ZRBaseViewController.m
//  SinaByOC
//
//  Created by 张锐 on 16/2/28.
//  Copyright © 2016年 zhangr. All rights reserved.
//

#import "ZRBaseViewController.h"
#import "ZRLoginViewController.h"
@interface ZRBaseViewController ()

@end

@implementation ZRBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.visitor = [[ZRVisitorView alloc]initWithFrame:self.view.bounds];
    
    
    __weak typeof(self) weakSelf = self;
    //通过代码块监听visitor注册按钮点击
    self.visitor.registerBlock=^(){
        
        
        ZRLoginViewController *loginVC = [[ZRLoginViewController alloc]init];
    //跳转注册页面控制器
        [weakSelf presentViewController:[[UINavigationController alloc]initWithRootViewController:loginVC ] animated:YES completion:^{}];
    
    };
    
    //通过通知监听visitor登录按钮点击
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loginButtonClick) name:@"loginButtonClick" object:self.visitor];
    
    self.view = self.visitor;
    
    [self setupNavButtons];
}


#pragma mark - nav相关
-(void)setupNavButtons{

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(registerButtonClick)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(loginButtonClick)];


}
/**
 *  注册按钮点击调用代码块
 */
-(void)registerButtonClick{

    self.visitor.registerBlock();

}
/**
 *  实现监听通知方法
 */
-(void)loginButtonClick{

    NSLog(@"登录了一下");

}

@end
